﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace EventSourceTest.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult TestEventSource()
        {
            
            return View();
        }

        public ActionResult EventSourceDateSource()
        {
            //Response.AppendHeader("Content-Type", "text/event-stream");
            ////note
            //Response.Write(":ack\n\n");
            ////event type
            //Response.Write("event: ping\n\n");
            //Response.Write(DateTime.Now);
            //Response.End();
            StringBuilder collect = new StringBuilder();
            collect.Append(":ack\n");
            collect.Append("retry: 10000\n");
            collect.Append("event: ping\n\n");
            collect.Append("data:"+DateTime.Now+"\n\n");
            return Content(collect.ToString(), "text/event-stream");
        }

        public ActionResult TestWebSocket()
        {
            return View();
        }

        public ActionResult WebSocketDataSource()
        {
            var obj = new 
            {
                Name="test case",
                Time = DateTime.Now
            };
            return Json(obj);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}